package edu.mobbuzz.daf.facade;

import java.util.ArrayList;
import java.util.List;

import edu.mobbuzz.daf.bean.Logs;
import edu.mobbuzz.daf.bean.Subscriber;
import edu.mobbuzz.daf.dao.ISubscriberDao;
import edu.mobbuzz.util.DBUtility;

public class SubscriberFacade extends BaseFacade {
	private ISubscriberDao subscriberDao;
	
	public ISubscriberDao getSubscriberDao() {
		if(subscriberDao==null)
			subscriberDao=(ISubscriberDao)getFactory().getBean("subscriberDao");
		return subscriberDao;
	}
	
	public boolean removeSubscriber(String id){
		try{
			getSubscriberDao().delete(id);		
			return true;
		}catch (Exception e) {
			return false;
		}
	}
	public boolean addSubscriber(String username, String url){
		Subscriber _subscriber = new Subscriber();
		_subscriber.setId(DBUtility.generateId());
		_subscriber.setUsername(username);
		_subscriber.setUrl(url);
		
		try{
			getSubscriberDao().insert(_subscriber);
			return true;
		}catch (Exception e) {
			return false;
		}
		
	}
	
	public List<Subscriber> getSubscriberList(String where, String order){
		List<Subscriber> subscriberList = getSubscriberDao().queryForList(where, order);
		
		if(subscriberList==null){
			subscriberList = new ArrayList<Subscriber>();
			return subscriberList;			
		}else{
			return subscriberList;
		}		
	}
	
	public boolean checkSubscriberExist(String username, String url){
		Subscriber _subscriber = (Subscriber) getSubscriberDao().queryForBaseBean("username='"+username+"' AND url='"+url+"' ");
		if(_subscriber!=null){
			return true;
		}else{
			return false;
		}
		
		
	}
}
